import com.touzi.beans.dbs.dingdan.NewDingdan;
import com.touzi.beans.dbs.liushui.Liushui;
import com.touzi.beans.dbs.liushui.NewLiushui;
import com.touzi.beans.dbs.tixian.NewTixian;
import com.touzi.beans.dbs.yongjin.NewYongjin;
import com.touzi.mapper.DingdanMapper;
import com.touzi.mapper.LiushuiMapper;
import com.touzi.mapper.TixianMapper;
import com.touzi.mapper.YongjinMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class InsertDBs {

    @Test
    public void insertYongjin() throws IOException {
        String resource = "mybatisconfig/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession=sqlSessionFactory.openSession();
        //yonghu | dingdan | cengji | jiner
        List<NewYongjin> yongjins=new ArrayList<>();

        YongjinMapper mapper=sqlSession.getMapper(YongjinMapper.class);
        mapper.insertNewReco(yongjins);

        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void insertNewtixian() throws IOException {
        String resource = "mybatisconfig/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession=sqlSessionFactory.openSession();

// //yonghuid | dingdanhao | jiner |
        List<NewTixian> tixians=new ArrayList<>();
        for (int i=0;i<100;i++){
            tixians.add(new NewTixian(2719147,Long.toString(System.currentTimeMillis()),9.9f));
        }
        TixianMapper mapper=sqlSession.getMapper(TixianMapper.class);
        mapper.insertNewReco(tixians);
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void insertNewdingdan() throws IOException {
        String resource = "mybatisconfig/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession=sqlSessionFactory.openSession();

//yonghuid | dingdanhao | chanpinid | dingdanjiner |
        List<NewDingdan> dingdans=new ArrayList<>();
        for (int i=0;i<100;i++){
            dingdans.add(new NewDingdan(2719147,Long.toString(System.currentTimeMillis()),1,9.9f));
        }
        DingdanMapper mapper=sqlSession.getMapper(DingdanMapper.class);
        mapper.insertNewReco(dingdans);
        sqlSession.commit();
        sqlSession.close();
    }

}
